<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" 		uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜系类别管理页面</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ttOrder/static/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ttOrder/static/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/ttOrder/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ttOrder/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ttOrder/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">

	var url;

	function deleteBlogType(){
		var selectedRows=$("#dg").datagrid("getSelections");
		if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要删除的数据！");
			 return;
		 }
		 var strIds=[];
		 for(var i=0;i<selectedRows.length;i++){
			 strIds.push(selectedRows[i].id);
		 }
		 var ids=strIds.join(",");
		 $.messager.confirm("系统提示","您确定要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
				if(r){
					$.post("${pageContext.request.contextPath}/ttOrder/delFood",{ids:ids},function(result){
						if(result.success){
							if(result.exist){
								 $.messager.alert("系统提示",result.exist);
							}else{
								 $.messager.alert("系统提示","数据已成功删除！");								
							}
							 $("#dg").datagrid("reload");
						}else{
							$.messager.alert("系统提示","数据删除失败！");
						}
					},"json");
				} 
	   });
	}
	
	function openBlogTypeAddDialog(){
		$("#dlg").dialog({width:500,height:300});
		resetValue();
		$("#dlg").dialog("open").dialog("setTitle","添加菜品");
		resetValue();
		url="${pageContext.request.contextPath}/ttOrder/addFood";
	}
	
	function openBlogTypeModifyDialog(){
		$("#dlg").dialog({width:500,height:300});
		var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		 var row=selectedRows[0];
		 $("#dlg").dialog("open").dialog("setTitle","编辑菜品信息");
		 $("#fm").form("load",row);
		 url="${pageContext.request.contextPath}/ttOrder/editFood?id="+row.id;
	 }
	
	function saveBlogType(){
		 $("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				}
			}
		 });
	 }
	 
	function resetValue(){
		 $("#foodName").val("");
		 $("#remark").val("");
		 $("#foodTypeId").val("");
		 $("#price").val("");
		 $("#mprice").val("");
		 $("#image").val("");
	 }
	
	 function closeBlogTypeDialog(){
		 $("#dlg").dialog("close");
		 resetValue();
	 }

	 function searchMenu(){
			$("#dg").datagrid('load',{
				"foods.foodName":$("#s_menuName").val()
			});
		}
	
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="菜品管理" class="easyui-datagrid"
   fitColumns="true" pagination="true" rownumbers="true"
   url="${pageContext.request.contextPath}/foodlist" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="id" width="20" align="center">菜品Id</th>
   		<th field="foodTypeId" width="50" align="center" >菜系</th>
   		<th field="foodName" width="50" align="center">名称</th>
   		<th field="remark" width="200" align="center">描述</th>
   		<th field="price" width="50" align="center">价格</th>
   		<th field="mprice" width="50" align="center">会员价格</th>
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<div>
 	    <a href="javascript:openBlogTypeAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
 		<a href="javascript:openBlogTypeModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
 		<a href="javascript:deleteBlogType()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
 	</div>
 	<div>
			&nbsp;菜品名称：&nbsp;<input type="text" id="s_menuName" size="20" onkeydown="if(event.keyCode==13) searchMenu()"/>
			<a href="javascript:searchMenu()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	</div>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
 </div>
 
 
 <div id="dlg" class="easyui-dialog" style="width:500px;height:180px;padding: 10px 20px"
   closed="true" buttons="#dlg-buttons">
   
   <form id="fm" method="post" enctype="multipart/form-data">
   	<table cellspacing="8px">
   	    <tr>
   			<td>菜品名称：</td>
   			<td><input type="text" id="foodName" name="foodName" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
	 		<td>所属菜系：</td>
	 		<td colspan="4"><input class="easyui-combobox" id="foodTypeId" name="foodTypeId" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'typeName',url:'${pageContext.request.contextPath}/foodtype'"/>
	 		</td>
	 	</tr>
   		<tr>
   			<td>菜品描述：</td>
   			<td><input type="text" id="remark" name="remark" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>菜品价格：</td>
   			<td><input type="text" id="price" name="price" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>菜品会员价格：</td>
   			<td><input type="text" id="mprice" name="mprice" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<!--  
   		<tr>
	 		<td>商品图片：</td>
	 		<td colspan="4"><input type="file" id="image" name="image" /></td>
	    </tr>
   		-->
   		
   		
   	</table>
   </form>
 </div>
 
 <div id="dlg-buttons">
 	<a href="javascript:saveBlogType()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
 	<a href="javascript:closeBlogTypeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
 </div>
</body>
</html>